import unittest
import os
from src.utest import list_file, fix_directory, check_string_list
from src.general_function import get_all_utest_dirs
from src.sup_function import get_test_data_path


class FileTest(unittest.TestCase):
    def test_count_file(self):
        actual = len(get_all_utest_dirs(os.path.join(get_test_data_path(), "test_count_file")))
        self.assertEqual(actual, 1)

    def test_list_file(self):
        file = os.path.join(get_test_data_path(), "utest.log")
        expected = len(list_file(file)) + 3
        with open(file, "r") as f:
            actual = len([i_string for i_string in f])
        self.assertEqual(expected, actual)

    def test_fix_directory_not_found(self):
        file = os.path.join(get_test_data_path(), "test_count_file123")
        self.assertFalse(fix_directory(file))

    def test_check_strings(self):
        utest_file = os.path.join(get_test_data_path(), "utesttest.log")
        with open(utest_file, "r") as f:
            actual = check_string_list([i for i in f])
            actual = (actual.name, actual.time)
            expected = ('GCM_Samples', 20)
            self.assertTupleEqual(actual, expected)

    # def test_reports_directory(self):
    #     folder = os.path.join(get_test_data_path(), "test_reports_directory")
    #     check_directory(folder)
    #     for i in get_all_utest_dirs(folder):
    #         if "results.json" in os.listdir(i):
    #             os.remove(os.path.join(i, "results.json"))
    #     # expected = ["rev_92380 CheckingStrategy.after_last_eval", "rev_92380 CheckingStrategy.full_check", "rev_92380 CheckingStrategy.full_determind_points"]
    #     # self.assertListEqual(actual, expected)


if __name__ == '__main__':
    unittest.main()